<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline" style="text-align: left">
      <el-form-item label="链接状态">
        <el-select v-model="formInline.connectionStatus">
          <el-option label="请选择" :value="0"></el-option>
          <el-option label="在线" :value="1"></el-option>
          <el-option label="离线" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备编号">
        <el-input v-model="formInline.equipMentNum"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getOledScreenlog">查询</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>

    <br>

    <el-table
      ref="multipleTable"
      border
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="equipMentNum" label="设备编号" align="center">
      </el-table-column>
      <el-table-column prop="createDate" label="创建时间" align="center">
      </el-table-column>
      <el-table-column prop="connectionStatus" label="连接状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.connectionStatus == true">在线</span>
          <span v-if="scope.row.connectionStatus == false">离线</span>
        </template>
      </el-table-column>
      <el-table-column prop="openStaus" label="开启状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.openStaus == true">开启</span>
          <span v-if="scope.row.openStaus == false">关闭</span>
        </template>
      </el-table-column>
      <el-table-column prop="openingTime" label="开启时间" align="center">
      </el-table-column>
      <el-table-column prop="closingTime" label="关闭时间" align="center">
      </el-table-column>
      <el-table-column prop="remark" label="备注" align="center">
      </el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-link type="danger" @click="deleteOledScreenlog(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>
  </div>
</template>
<script>
import {
  getoledScreenlogapi,
  deleteoledScreenlogapi,
} from "@/api/iotInfo/oledScreen";
export default {
  data() {
    return {
      tableData: [],
      multipleSelection: [],
      count: 0,
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        connectionStatus: 0,
        equipMentNum: "",
      },
      oledform: {},
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.oledform = {};
      this.oledform = val[0];
    },
    resetForm() {
      (this.formInline.connectionStatus = 0),
        (this.formInline.equipMentNum = "");
    },
    getOledScreenlog() {
      getoledScreenlogapi(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
      this.getOledScreenlog();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageIndex = val;
      this.getOledScreenlog();
    },
    deleteOledScreenlog(row) {
      if (confirm("确定要删除吗？")) {
        deleteoledScreenlogapi(row).then((res) => {
          if (res.data.message == "操作成功") {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getOledScreenlog();
          } else {
            this.$message({
              message: "删除失败",
              type: "error",
            });
          }
        });
      }
    },
  },
  created() {
    this.getOledScreenlog();
  },
};
</script>
<style></style>